package com.noahplat.user.mapper;

import com.noahplat.user.pojo.Menu;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 菜单栏关系映射
 *
 * @author 李东
 * @version 1.0.0
 * @Date: 2021/2/27 13:39
 **/
public interface MenuMapper extends Mapper<Menu> {

    @Select("select m.id,m.title,m.url,m.active,m.inactive,m.parentid from tb_role_menu rm left join tb_menu m on rm.mid = m.id where m.parentid=#{parentid} and m.stid=#{stid} and rm.rid=#{rid} and del='N' ")
    List<Map<String, Object>> findMenuListByPid(@Param("parentid") long parentid, @Param("stid") String stid, @Param("rid") Long rid);

    @Select("select id,title,url,active,inactive,parentid from tb_menu where id=#{id} and stid=#{stid} and del='N' and  parentid is null")
    Map<String, Object> selectOneById(@Param("id") long id, @Param("stid") String stid);

    @Insert("<script> INSERT INTO tb_menu(stid,acctid,title,url,active,inactive,parentid,del) VALUES <foreach collection = 'list' item='record' separator=','>" +
            "(#{stid},#{acctid},#{record.title},#{record.url},#{record.active},#{record.inactive},#{record.parentid},#{record.del})</foreach></script>")
    int insertMenu(@Param("stid")Long stid,@Param("acctid")Long acctid,@Param("list")List<Menu> list);

    @Select("select id from tb_menu where stid=#{stid} and acctid=#{acctid}")
    Set<Long> getMid(@Param("stid") Long stid,@Param("acctid") Long acctid);
}
